package com.example.swimmingpool.controller.wx;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.swimmingpool.entity.booking.Booking;
import com.example.swimmingpool.enums.HttpEnum;
import com.example.swimmingpool.qo.base.BaseQo;
import com.example.swimmingpool.response.CommonResponse;
import com.example.swimmingpool.service.wx.WxBookingService;
import com.example.swimmingpool.service.wx.WxService;
import com.example.swimmingpool.service.wx.WxUserService;
import com.example.swimmingpool.vo.wx.WxBookingVo;
import com.example.swimmingpool.vo.wx.WxCodeVo;
import com.example.swimmingpool.vo.wx.WxUserVo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/wx")
@Slf4j
public class WxController {
    @Resource
    private WxService wxService;

    @Resource
    private WxBookingService wxBookingService;

    @Resource
    private WxUserService wxUserService;

    @PostMapping("/login")
    public CommonResponse<String> getWxInfo(@RequestBody WxCodeVo vo) throws IOException {

        String s = wxService.wxLogin(vo);
        return CommonResponse.success(s, HttpEnum.LOGIN_ACCOUNT_SUCCESS.getMsg());

    }

    @PostMapping("/booking")
    public CommonResponse<Boolean> booking(@RequestBody WxBookingVo vo) {
        return CommonResponse.success(wxBookingService.booking(vo));

    }

    @PostMapping("/count")
    public CommonResponse<Long> getPeopleCount() {
        return CommonResponse.success(wxBookingService.getPeopleCount());

    }

    @PostMapping("/booking/list")
    public CommonResponse<List<Booking>> getMyBooking() {
        return CommonResponse.success(wxBookingService.getMyBooking());
    }

    @PostMapping("/today/booking")
    public CommonResponse<Boolean> getTodayBooking() {
        return CommonResponse.success(wxBookingService.isTodayBooking());
    }

    @PostMapping("/list")
    public CommonResponse<IPage<WxUserVo>> getUserList(@RequestBody BaseQo qo) {
        return CommonResponse.success(wxUserService.getUser(qo));
    }


}
